// 音乐播放器
import { _getMusicUrl } from 'network/detail'
import { PlayList } from 'components/content/playmusic/playList'
export const indexMixin = {
  methods: {
    PlayMusic (index = 0) {
      const path = this.$route.path
      var musiclist
      if (this.musiclist.length >= 200) {
        musiclist = this.musiclist.slice(0, 199)
      } else musiclist = this.musiclist
      var url = null
      let currentLength = 0;
      const playlist = []
      for (let i = 0, length = musiclist.length; i < length; i++) {
        _getMusicUrl(musiclist[i].id).then(res => {
          // 音源
          url = res.data.data[0].url
          const song = new PlayList(i, musiclist[i], url, musiclist[i].id)
          playlist.push(song)
          currentLength++;
          if (i == musiclist.length - 1) {
            // 事件总线，发射playMusic事件(向PlayMusic发射)
            this.$bus.$emit('playMusic', playlist, index, path, musiclist)
          }
        })
      }
    }
  }
}
